package com.changgou.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changgou.framework.entity.PageResult;
import com.changgou.goods.dao.ParaDao;
import com.changgou.goods.service.ParaService;
import com.haha.goods.entity.Para;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Yang
 * @date 2020/11/7
 */
@Service
public class ParaServiceImpl extends ServiceImpl<ParaDao, Para> implements ParaService {
    @Override
    public PageResult findPage(Para para, int page, int size) {
        QueryWrapper<Para> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(para)){
            queryWrapper.eq(para.getId()!=null,"id",para.getId());
            queryWrapper.eq(para.getSeq()!=null,"seq",para.getSeq());
            queryWrapper.eq(!StringUtils.isEmpty(para.getOptions()),"options",para.getOptions());
            queryWrapper.eq(para.getTemplateId()!=null,"template_id",para.getTemplateId());
            queryWrapper.like(!StringUtils.isEmpty(para.getName()),"name",para.getName());
        }
        Integer count = baseMapper.selectCount(queryWrapper);
        int offset = (page-1)*size;
        List<Para> paras = baseMapper.findPage(queryWrapper,offset,size);
        return null;
    }

    @Override
    public List<Para> findByCategoryId(Integer id) {
        return baseMapper.findByCategoryId(id);
    }
}
